package com.zpark.cz.simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.zpark.cz.util.ConnectionUtil;

import java.io.IOException;


import java.util.concurrent.TimeoutException;

public class Producer {
    private static final String  QUEUE_NAME = "A1.queue";
    public static void main(String[] args) throws IOException, TimeoutException {
        // 获取连接
        Connection conn = ConnectionUtil.getConnection();
        // 从连接中创建通道
        Channel channel = conn.createChannel();
        // 声明队列（创建一个队列）
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        // 消息内容
        String msg = "Hello, World!";
        // 将消息放入队列
        channel.basicPublish("", QUEUE_NAME, null, msg.getBytes());
        // 打印输出内容到控制台，方便查看，做测试用
        System.out.println(msg);
        // 关闭通道，关闭连接
        channel.close();
        conn.close();
    }
}
